/**
 * Copyright (C), 2018-2018, 河北东软有限公司
 * FileName: hello
 * Author:   Administrator
 * Date:     2018/4/24 12:01
 * Description: 测试
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package pers.fqq.dlfd.student.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import pers.fqq.dlfd.student.entity.StudentEntity;
import pers.fqq.dlfd.student.service.StudentService;

import java.io.IOException;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈测试〉
 *
 * @author Administrator
 * @create 2018/4/24
 * @since 1.0.0
 */
@Controller
public class Hello {


    @Autowired
    StudentService studentService;

    @RequestMapping("/")
    public String index() {
        return "redirect:/list";
    }

    @GetMapping("/list")
    public String list(Model model){
        List<StudentEntity> users = studentService.findAll();
        model.addAttribute("users", users);
        return "user/list";
    }
//
//    @RequestMapping("/toAdd")
//    public String toAdd() {
//        return "user/userAdd";
//    }
//
//    @RequestMapping("/add")
//    public String add(StudentEntity user) {
//        studentService.save(user);
//        return "redirect:/list";
//    }
//
    @GetMapping("/toEdit")
    public String toEdit(Model model, String id) {
        StudentEntity user = studentService.findOne(id);
        model.addAttribute("user", user);
        return "user/userEdit";
    }

    @PostMapping("/edit")
    public String edit(StudentEntity user) {
        studentService.save(user);
        return "redirect:/list";
    }
//
//
//    @RequestMapping("/delete")
//    public String delete(Long id) {
//        studentService.delete(id);
//        return "redirect:/list";
//    }

    @RequestMapping("/layout")
    public String layout() {
        return "layout";
    }


}